

// 操作顶部信息

//点击打开顶部下拉框
function shouHeaderInfoFun(){
    let headerMenu = document.getElementsByClassName("headerMenu")[0];
    if(headerMenu.getAttribute("flag")==0){
        headerMenu.style.display = "block";
        headerMenu.setAttribute("flag", "1")
    }else{
        headerMenu.style.display = "none";
        headerMenu.setAttribute("flag", "0")
    }
}
//点击打开顶部消息管理
function shouMessageFun(){
    let messageMenu = document.getElementsByClassName("messageMenu")[0];
    if(messageMenu.getAttribute("flag")==0){
        messageMenu.style.display = "block";
        messageMenu.setAttribute("flag", "1")
    }else{
        messageMenu.style.display = "none";
        messageMenu.setAttribute("flag", "0")
    }
}
async function messageInitFun(){
    let messages = document.getElementsByClassName("messages")[0];
    let storeNum = await getStoreApplyFun()
    let usersNum = await getStoreApplyFun()
    let goodsNum = await getGoodsApplyFun()
    let messageNum = document.getElementsByClassName('messageNum')
    messageNum[0].innerHTML = storeNum+usersNum+goodsNum;
    messageNum[1].innerHTML = storeNum;
    messageNum[2].innerHTML = usersNum;
    messageNum[3].innerHTML = goodsNum;
    messages.style.display="block"
}
messageInitFun()
function getStoreApplyFun(){
    return new Promise((resolve, reject) => {
        axios({
            url:'/admin/store/findAllBussiness',
            method:'GET',
            params:{
                page:1,
                size:1
                }
            })
            .then(data => {
                if(data.data.code==20000){
                    resolve(data.data.data.totalCounts);
                }else{
                    resolve(0)
                }
            })
            .catch(err => {
                console.log(err);
            })
    });
}
function getUserApplyFun(){
    return new Promise((resolve, reject) => {
        axios({
            url:'/admin/users/findAllRealName',
            method:'GET',
            params:{
                page:1,
                size:1,
                flag:0
                }
            })
            .then(data => {
                if(data.data.code==20000){
                    resolve(data.data.data.totalCounts);
                }else{
                    resolve(0)
                }
            })
            .catch(err => {
                console.log(err);
            })
    });
}
function getGoodsApplyFun(){
    return new Promise((resolve, reject) => {
        axios({
            url:'/admin/goods/findGoodsByFlag',
            method:'GET',
            params:{
                page:1,
                size:1,
                flag:0
                }
            })
            .then(data => {
                if(data.data.code==20000){
                    resolve(data.data.data.totalCounts);
                }else{
                    resolve(0)
                }
            })
            .catch(err => {
                console.log(err);
            })
    });
}
// 操作左侧下拉菜单
var showMenu=0;
var menuList = document.getElementsByClassName("menuList");
for(let i=0;i<menuList.length;i++){
    menuList[i].onclick=function(){
        let index = this.getAttribute("target");
        if(this.getAttribute("flag")=="false"){
            menuList[index].style.height="auto";
            this.setAttribute("flag","true");
            if(index != showMenu){
                menuList[showMenu].style.height="40px";
                menuList[showMenu].setAttribute("flag","false");
                showMenu = index;
            }
        }else{
            menuList[index].style.height="40px";
            this.setAttribute("flag","false");
        }
    }
}


// 操作分页
var pages = 1, pageSize = 10, current=1,counts=10;
var showAll = false;
function updataFun(e){
    e=e || window.event;
    var target=e.target || e.srcElement;
    current = target.getAttribute("name");
    console.log(current);   
    console.log(pages);
    handleoageFun(current,pages);
    fun(1);
}
function handleoageFun(a,b){//a代表第几页，b代表共几页
    console.log(a,b);
    let pages = document.getElementsByClassName("pages")[0];
    let prev =document.getElementsByClassName("prev")[0];
    let next =document.getElementsByClassName("next")[0];
    let searchByPage = document.getElementsByClassName("searchByPage")[0];
    if(a==1){
        prev.setAttribute("disabled",true);
        prev.setAttribute("id","prevId");
    }else if(a==b){
        next.setAttribute("disabled",true);
        next.setAttribute("id","nextId");
    }else{
        next.removeAttribute("disabled");
        next.removeAttribute("id");
        prev.removeAttribute("disabled");
        prev.removeAttribute("id");
    }
    // 页数按钮处理
    if(b<=7){
        pages.innerHTML ="";
        for(let i=1;i<=b;i++){
            console.log(a);
            pages.innerHTML +=`
                 <span class="${i==a?"activePage":"waitPage"}" name="${i}" onclick="updataFun()">${i}</span>
                `
        }
    }else{
        if(a<=4){
            pages.innerHTML ="";
            for(let i=1;i<=7;i++){
                if(i==a){
                    pages.innerHTML +=`
                    <span class="activePage" name="${i}" onclick="updataFun()">${i}</span>
                    `
                }else if(i==6){
                    pages.innerHTML +=`
                    <span class="dotRight">...</span>
                    `
                }else if(i==7){
                    pages.innerHTML +=`
                    <span class="waitPage" name="${b}" onclick="updataFun()">${b}</span>
                    `
                }else{
                    pages.innerHTML +=`
                    <span class="waitPage" name="${i}" onclick="updataFun()">${i}</span>
                    `
                }
            }
        }else if(a>=(b-2)){
            pages.innerHTML ="";
            pages.innerHTML +=`
                <span class="waitPage" name="1" onclick="updataFun()">1</span>
                <span class="dotLeft">...</span>
                <span class="waitPage" name="${b-4}" onclick="updataFun()">${b-4}</span>
                <span class="waitPage" name="${b-3}" onclick="updataFun()">${b-3}</span>
            `
            for(let i=b-2;i<=b;i++){
                pages.innerHTML +=`
                    <span class="${i==a?"activePage":"waitPage"}" name="${i}" onclick="updataFun()">${i}</span>
               `
            }

        }else{
            pages.innerHTML ="";
            pages.innerHTML +=`
                <span class="waitPage" name="1" onclick="updataFun()">1</span>
                <span class="dotLeft">...</span>
                
            `
            a=parseInt(a)
            for(let i=(a-1);i<=(a+1);i++){
                pages.innerHTML +=`
                <span class="${i==a?"activePage":"waitPage"}" name="${i}" onclick="updataFun()">${i}</span>
                `
            }
            pages.innerHTML +=`
            <span class="dotLeft">...</span>
            <span class="waitPage" name="${b}" onclick="updataFun()">${b}</span>
                `
        }
        
    }
    searchByPage.value=a;
}


// 上一页
let prev =document.getElementsByClassName("prev")[0];
let next =document.getElementsByClassName("next")[0];
function prevFun(){
    next.removeAttribute("disabled");
    next.removeAttribute("id");
    if(current>1){
        current--;
        if(current==1){
            prev.setAttribute("disabled",true);
            prev.setAttribute("id","prevId");
        }

    }
    fun(1);
}
// 下一页
function nextFun(){
    prev.removeAttribute("disabled");
    prev.removeAttribute("id");
    console.warn(current);
    console.warn(pages);
    if(current<pages){
        current++;
        console.log(current==pages);
        // handleoageFun(current,pages);
        pageFun({current,pages,counts})
        if((current==pages)==true){
            console.log(next);
            next.setAttribute("disabled",true);
            next.setAttribute("id","nextId");
        }
    }
    fun(1);
}

function pageFun({current,pages,counts,pageSize}){
    // 处理核心分页
    handleoageFun(current,pages)
    perPageSizeFun(counts,pageSize);
    // 下一页按钮处理
    countPageFun(pages);
   
}
// 每页显示条数
function perPageSizeFun(counts,pageSize) {
    let selectNums = document.getElementById("selectNums");
    let dataNums =cl("dataNums");
    dataNums.innerHTML=counts;
    selectNums.innerHTML=" ";
    console.warn(pageSize);
    if(counts<10){
        selectNums.innerHTML+=`
        <option value="10" class="options">${counts}</option>
        `
        // handleoageFun(current,1)
    }else if(counts>=10 && counts<20){
        if(pageSize>10 && pageSize<20){
            selectNums.innerHTML+=`
            <option value="${counts}" class="showAllOption">${counts}</option>
            <option value="10" >10</option>
            `
        }else{
            selectNums.innerHTML+=`
            <option value="10">10</option>
            <option value="${counts}" class="showAllOption">${counts}</option>
            `
        }
    }else if(counts>=20 && counts<50){
        if(pageSize==20){
            selectNums.innerHTML+=`
            <option value="20"  >20</option>
            <option value="10">10</option>
            <option value="${counts}" class="showAllOption">${counts}</option>
            `
        }else if(pageSize>20 && counts<50){
            selectNums.innerHTML+=`
            <option value="${counts}" checked="checked" class="showAllOption">${counts}</option>
            <option value="10">10</option>
            <option value="20">20</option>
            `
        }else{
            selectNums.innerHTML+=`
            <option value="10">10</option>
            <option value="20">20</option>
            <option value="${counts}"class="showAllOption">${counts}</option>
            `
        }
        
    }else{
        console.log(counts);
        if(pageSize==20){
            console.log(pageSize);
            selectNums.innerHTML+=`
            <option value="20" checked="checked">20</option>
            <option value="10">10</option>
            <option value="50">50</option>
            <option value="${counts}" class="showAllOption">${counts}</option>
            `
        }else if(pageSize==50){
            selectNums.innerHTML+=`
            <option value="50" checked="checked">50</option>
            <option value="10">10</option>
            <option value="20">20</option>
            <option value="50" checked="checked">50</option>
            <option value="${counts}" class="showAllOption">${counts}</option>
            `
        }else if(pageSize>50){
            selectNums.innerHTML+= `
            <option value="${counts}" checked="checked" class="showAllOption">${counts}</option>
            <option value="10">10</option>
            <option value="20">20</option>
            <option value="50">50</option>
            `
        }else{
            selectNums.innerHTML+= `
            <option value="10">10</option>
            <option value="20">20</option>
            <option value="50">50</option>
            <option value="${counts}" class="showAllOption">${counts}</option>
            `
        }
        
    }
}
// 点击跳转到指定页码
function changePageFun(){
    let searchByPage = document.getElementsByClassName("searchByPage")[0];
    let result = searchByPage.value;
    result = parseInt(result);
    if((result>0)==false &&(result<0)==false && (result==0)==false){
        alert("请输入正确的页数")
    }else if(result<=0){ 
        current = 1;
        handleoageFun(1,pages);
    }else if(result>pages){
        current = pages;
        handleoageFun(result,pages);
    }else{
        current = result;
        handleoageFun(result,pages);
    }
    if((result>0)=="false" && (result<0)=="false" && (result==0)=="false"){
        alert("请输入正确的页码")
    }
    fun(); 
}
// 计算总页数
function countPageFun(pages){
    // if(counts%pageSize==0){
    //     pages=counts/pageSize;
    // }else{
    //     pages=counts/pageSize;
    //     pages = parseInt(pages)+1;
    // }
    console.log(pages);
    if(pages==1){
        next.setAttribute("disabled",true);
        next.setAttribute("id","nextId");
    }else{
        next.removeAttribute("disabled");
        next.removeAttribute("id");
    }
}

//显示当前时间 
let time = document.getElementsByClassName("time")[0];
showRealTime(time)
function showRealTime(clock){
    var d = new Date();
    var year = d.getFullYear();
    var month = d.getMonth() + 1;
    var date = d.getDate();
    var days = new Array("日","一","二","三","四","五","六");
    var day = d.getDay();
    var hour = (d.getHours() < 10) ? ("0" + d.getHours()) : d.getHours();
    var min = (d.getMinutes() < 10) ? ("0" + d.getMinutes()) : d.getMinutes();
    var sec = (d.getSeconds() < 10) ? ("0" + d.getSeconds()) : d.getSeconds();
    var now = year + "年" + month + "月" + date + "日 " + hour + ":" + min + ":" + sec +" 星期" +days[day];
    clock.innerHTML = now;
}
function load(){
    window.setInterval('showRealTime(time)',1000);
}
load();


// alert函数封装
function closeFun(){
    alertWindow = document.getElementsByClassName("alertWindow")[0];
    let covers = document.getElementsByClassName("covers")[0];
    // let addUserWindow = document.getElementsByClassName("addUserWindow")[0];
    covers.style.display = "none";
    alertWindow.style.display = "none";
    // addUserWindow.style.display = "none";
    // let changeImgWin = cl("changeImgWin");
    // changeImgWin.style.display ='none';
    // let userInfoWindow = cl("userInfoWindow");
    // userInfoWindow.style.display ='none';
}
// 0:普通的alert弹窗
// 1:批量删除用户
// 2:删除用户
// 3:删除店铺
// 4:批量删除店铺
// 5:通过店铺审核
// 6:批量删除订单
// 7:删除单个订单
// 8:删除单个商品
// 9:批量删除商品
// 10.通过一个商品
// 11.退出登录
// 12.删除一条评论
// 13.批量删除评论
// 14.通过实名认证
// 15.拒绝实名认证
function pointFun({code,msg}){
    let alertMsg = document.getElementsByClassName("alertMsg")[0];
    let alertWindow = document.getElementsByClassName("alertWindow")[0];
    let alertTitle = document.getElementsByClassName("alertTitle")[0];
    let alertBtn = document.getElementsByClassName("alertBtn")[0];
    let covers = document.getElementsByClassName("covers")[0];
    alertMsg.innerHTML = msg;
    if(code==0){
        alertTitle.innerHTML ='提示信息'
        alertBtn.setAttribute('name','0')
    }else if(code == 1){
        alertBtn.setAttribute('name','1')
        alertTitle.innerHTML ='批量删除用户'
    }else if(code == 2){
        alertBtn.setAttribute('name','2')
        alertTitle.innerHTML ='删除用户'
    }else if(code == 3){
        alertBtn.setAttribute('name','3')
        alertTitle.innerHTML ='删除店铺'
    }else if(code == 4){
        alertBtn.setAttribute('name','4')
        alertTitle.innerHTML ='批量删除店铺'
    }else if(code ==5){
        alertBtn.setAttribute('name','5')
        alertTitle.innerHTML ='通过审核'
    }else if(code ==6){
        alertBtn.setAttribute('name','6')
        alertTitle.innerHTML ='批量删除订单'
    }else if(code==7){
        alertBtn.setAttribute('name','7')
        alertTitle.innerHTML ='删除订单'
    }else if(code==8){
        alertBtn.setAttribute('name','8')
        alertTitle.innerHTML ='删除商品'
    }else if(code==9){
        alertBtn.setAttribute('name','9')
        alertTitle.innerHTML ='批量删除商品'
    }else if(code ==10){
        alertBtn.setAttribute('name','10')
        alertTitle.innerHTML ='通过一个商品'
    }else if(code ==11){
        alertBtn.setAttribute('name','11')
        alertTitle.innerHTML ='退出登录'
    }else if(code ==12){
        alertBtn.setAttribute('name','12')
        alertTitle.innerHTML ='删除评论'
    }else if(code ==13){
        alertBtn.setAttribute('name','13')
        alertTitle.innerHTML ='批量删除评论'
    }else if(code ==14){
        alertBtn.setAttribute('name','14')
        alertTitle.innerHTML ='通过实名认证'
    }else if(code ==15){
        alertBtn.setAttribute('name','15')
        alertTitle.innerHTML ='拒绝实名认证'
    }
    console.log(covers);
    covers.style.display = "block";
    alertWindow.style.display = "block";
}
function closeFunBtn(){
    let alertBtn = document.getElementsByClassName("alertBtn")[0];
    if(alertBtn.getAttribute('name')==0){
        closeFun()
    }else if(alertBtn.getAttribute('name')==1){
        deleteUsersFun();
        closeFun()
    }else if(alertBtn.getAttribute('name')==2){
        deleteUserFun();
        closeFun()
    }else if(alertBtn.getAttribute('name')==3){
        deleteStoreFun();
        closeFunStore();
    }else if(alertBtn.getAttribute('name')==4){
        deleteStoresFun();
        closeFunStore();
    }else if(alertBtn.getAttribute('name')==5){
        submitPassFun();
        closeReasonWin();
    }else if(alertBtn.getAttribute('name')==6){
        deleteOrdersFun();
        closeOrderWin();
    }else if(alertBtn.getAttribute('name')==7){
        deleteOrderFun();
        closeOrderWin();
    }else if(alertBtn.getAttribute('name')==8){
        deleteGoodsFun();
        closeGoodsWin();
    }else if(alertBtn.getAttribute('name')==9){
        deleteGoodsAllFun();
        closeGoodsWin();
    }else if(alertBtn.getAttribute('name')==10){
        passGoodsFun();
        closeFun();
    }else if(alertBtn.getAttribute('name')==11){
        loginOutFun();
        closeFun();
    }else if(alertBtn.getAttribute('name')==12){
        deleteStoreCommentFun();
        closeFun();
    }else if(alertBtn.getAttribute('name')==13){
        deleteStoresCommentFun();
        closeFun();
    }else if(alertBtn.getAttribute('name')==14){
        passRealNameFun();
        closeFunUser();
    }else if(alertBtn.getAttribute('name')==15){
        refuseRealNameFun();
        closeFunUser();
    }

}
// pointFun({code:1,msg:'提示信息测试'})
// 提示信息封装
let timerExplain;
function explain({code,msg,time}){
    let explainIcon = document.getElementById("explainIcon");
    let explainMsg = document.getElementsByClassName("explainMsg")[0];
    let explain = document.getElementsByClassName("explain")[0];
    clearInterval(timerExplain);
    explain.style.display="block";
    if(code==1){
        explainIcon.setAttribute("class","iconfont chenggong");
    }else if(code==2){
        explainIcon.setAttribute("class","iconfont shibai");
    }else if(code==3){
        explainIcon.setAttribute("class","iconfont jinggao");
    }else{
        alert("参数错误");
        explain.style.display="none";
        return false;
    }
    explainMsg.innerHTML = msg;
    timerExplain= setInterval(function(){ 
        explain.style.display="none";
    },time)
}
// 示例
// explain({
//     code:3,
//     msg:"操作失败",
//     time:3000
// })
// alert("123");


// 封装一个类选择器
const cl = name=>{
    return document.getElementsByClassName(name)[0];
}
// console.log(cl("dataFour"));


// 选择出生年月日的函数
{
    function DateSelector(selYear, selMonth, selDay) {//定义函数
        this.selYear = selYear;
        this.selMonth = selMonth;
        this.selDay = selDay;
        this.selYear.Group = this;
        this.selMonth.Group = this;
      // 给年份、月份下拉菜单添加处理onchange事件的函数
        if (window.document.all != null) // IE
        {
          this.selYear.attachEvent("onchange", DateSelector.Onchange);
          this.selMonth.attachEvent("onchange", DateSelector.Onchange);
        }
        else // Firefox
        {
          this.selYear.addEventListener("change", DateSelector.Onchange, false);
          this.selMonth.addEventListener("change", DateSelector.Onchange, false);
        }
        if (arguments.length == 4) // 如果传入参数个数为4，最后一个参数必须为Date对象
          this.InitSelector(arguments[3].getFullYear(), arguments[3].getMonth() + 1, arguments[3].getDate());
        else if (arguments.length == 6) // 如果传入参数个数为6，最后三个参数必须为初始的年月日数值
          this.InitSelector(arguments[3], arguments[4], arguments[5]);
        else // 默认使用当前日期
        {
          var dt = new Date();
          this.InitSelector(dt.getFullYear(), dt.getMonth() + 1, dt.getDate());
        }
      }
      // 增加一个最小年份的属性--最老年份
      DateSelector.prototype.MinYear = 1960;
      // 增加一个最大年份的属性--最新年份，即当前时期getFullYear()
      DateSelector.prototype.MaxYear = (new Date()).getFullYear();
      // 初始化年份
      DateSelector.prototype.InitYearSelect = function () {
      // 循环添加OPION元素到年份select对象中
        for (var i = this.MaxYear; i >= this.MinYear; i--) {
      // 新建一个OPTION对象
          var op = window.document.createElement("OPTION");
      // 设置OPTION对象的值
          op.value = i;
      // 设置OPTION对象的内容
          op.innerHTML = i;
      // 添加到年份select对象
          this.selYear.appendChild(op);
        }
      }
      // 初始化月份
      DateSelector.prototype.InitMonthSelect = function () {
      // 循环添加OPION元素到月份select对象中
        for (var i = 1; i < 13; i++) {
      // 新建一个OPTION对象
          var op = window.document.createElement("OPTION");
      // 设置OPTION对象的值
          op.value = i;
      // 设置OPTION对象的内容
          op.innerHTML = i;
      // 添加到月份select对象
          this.selMonth.appendChild(op);
        }
      }
      // 根据年份与月份获取当月的天数
      DateSelector.DaysInMonth = function (year, month) {
        var date = new Date(year, month, 0);
        return date.getDate();
      }
      // 初始化天数
      DateSelector.prototype.InitDaySelect = function () {
      // 使用parseInt函数获取当前的年份和月份
        var year = parseInt(this.selYear.value);
        var month = parseInt(this.selMonth.value);
      // 获取当月的天数
        var daysInMonth = DateSelector.DaysInMonth(year, month);
      // 清空原有的选项
        this.selDay.options.length = 0;
      // 循环添加OPION元素到天数select对象中
        for (var i = 1; i <= daysInMonth; i++) {
      // 新建一个OPTION对象
          var op = window.document.createElement("OPTION");
      // 设置OPTION对象的值
          op.value = i;
      // 设置OPTION对象的内容
          op.innerHTML = i;
      // 添加到天数select对象
          this.selDay.appendChild(op);
        }
      }
      // 处理年份和月份onchange事件的方法，它获取事件来源对象（即selYear或selMonth）
      // 并调用它的Group对象（即DateSelector实例，请见构造函数）提供的InitDaySelect方法重新初始化天数
      // 参数e为event对象
      DateSelector.Onchange = function (e) {
        var selector = window.document.all != null ? e.srcElement : e.target;
        selector.Group.InitDaySelect();
      }
      // 根据参数初始化下拉菜单选项
      DateSelector.prototype.InitSelector = function (year, month, day) {
      // 由于外部是可以调用这个方法，因此我们在这里也要将selYear和selMonth的选项清空掉
      // 另外因为InitDaySelect方法已经有清空天数下拉菜单，因此这里就不用重复工作了
        this.selYear.options.length = 0;
        this.selMonth.options.length = 0;
      // 初始化年、月
        this.InitYearSelect();
        this.InitMonthSelect();
      // 设置年、月初始值
        this.selYear.selectedIndex = this.MaxYear - year;
        this.selMonth.selectedIndex = month - 1;
      // 初始化天数
        this.InitDaySelect();
      // 设置天数初始值
        this.selDay.selectedIndex = day - 1;
      }
}

// 过滤输入框标签
function htmlEscape(text){
    return text.replace(/[<>"&]/g,function(match,pos,originalText){
        switch(match){
        case "<":return "&lt";
        case ">":return "&gt";
        }
    });
}

 // 对表单的处理
 function  serialize(target) {
    let arrFormData = [], objFormData = {},rel = {};
    [].slice.call(target.elements).forEach(function (ele) {
        let type = ele.type,disabled = ele.disabled,name = ele.name,value = encodeURIComponent(ele.value || '');
        if(!name || disabled || !type ||(/^reset|submit|image$/i.test(type)) || (/^checkbox|radio$/i.test(type) && !ele.checked)){
          return;
        }
        type = type.toLocaleLowerCase();
        if(type !== 'select-multiple') {
            if (objFormData[name]) {
                objFormData[name].push(value);
            } else {
                objFormData[name] = [value];
            }
        }else{
          [].slice.call(ele.querySelector('option')).forEach(function (option) {
            let optionValue = encodeURIComponent(option.value || '');
            if(option.selected){
              if(objFormData[name]){
                objFormData[name].push(optionValue);
              }else{
                objFormData[name] = [optionValue];
              }
            }
          });
        }
    });
    for(let key in objFormData){


      arrFormData.push(key+'='+objFormData[key].join());
    }
    // return arrFormData.join('&');
    return objFormData;
}


// 正则表达式的封装
{
    // 电话号码判断
    function isTelCode(str) {
        var reg= /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/
        return reg.test(str);
    }
    // qq邮箱判断
    function isEmail(str) {
        var reg= /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/
        return reg.test(str);
    }

}

// 批量操作
var dels = new Array();
var checkbox  = document.getElementsByClassName("checkbox ");
function checkboxFun (e){
    e=e || window.event;
    var target=e.target || e.srcElement;
    console.log(target.getAttribute("name"));
    if(e.target.checked==false&&dels.length>0){
        dels.splice(dels.indexOf(e.target.getAttribute("name"),1))
    }
    let index = 0;
    for (let keys of checkbox) {
        if(keys.checked==true) {
            dels[index] =keys.name;
            index++;
        }
    }
    if((index)==checkbox.length){
        checkAll.checked = true;
    }else{
        checkAll.checked = false;
    }
  
}
function checkAllFun(){
    if(checkAll.checked){
        for (let key of checkbox){
            key.checked = true;
        }
        checkboxFun();
    }else{
        for (let key of checkbox){
            key.checked = false;
            dels.splice(dels.indexOf(key.name),1)
        }
        checkboxFun();
    }
    
}

function changePage(){
    checkAll.checked=false;
    for (let key of checkbox){
        key.checked = false;
        dels.splice(dels.indexOf(key.name),1)
    }
}


// 询问是否退出
function openLoginOut(){
    pointFun({
        code:11,
        msg:"是否确认退出登录？"
    })
}
function loginOutFun(){
    axios({
        url:'/admin/loginOut',
        method:'GET',
        })
        .then(data => {
            explain({
                code:1,
                msg:"退出登录成功",
                time:3000
            })
            location.href = "/home/login"
        })
        .catch(err => {
            console.log(err);
        })
}

// 处理价格：保留两位小数
function handlePrice(price){
    return parseFloat(price).toFixed(2);
}


